package com.example.shuiyin.controller;

import com.example.shuiyin.dto.ApiResponse;
import com.example.shuiyin.dto.payment.PaymentStatusResponse;
import com.example.shuiyin.service.PaymentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/payment")
@RequiredArgsConstructor
public class PaymentController {

    private final PaymentService paymentService;

    @PostMapping("/webhook")
    public String handleWebhook(@RequestBody String payload) {
        return paymentService.handleWebhook(payload);
    }

    @GetMapping("/status/{orderId}")
    public ApiResponse<PaymentStatusResponse> getPaymentStatus(@PathVariable String orderId) {
        return ApiResponse.success("获取支付状态成功", paymentService.getPaymentStatus(orderId));
    }

    @PostMapping("/cancel/{orderId}")
    public ApiResponse<Void> cancelPayment(@PathVariable String orderId) {
        paymentService.cancelPayment(orderId);
        return ApiResponse.success("支付已取消");
    }
} 